import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/store/provider/store_count_model.dart';
import 'package:provider/provider.dart';

class ShoppingBottowView extends StatefulWidget {
  const ShoppingBottowView({Key? key}) : super(key: key);

  @override
  _ShoppingBottowViewState createState() => _ShoppingBottowViewState();
}

class _ShoppingBottowViewState extends State<ShoppingBottowView> {
  /// 标记选中状态
  bool is_select = false;

  @override
  Widget build(BuildContext context) {
    return Container(
        width: MediaQuery.of(context).size.width,
        height: 45,
        color: Colors.white,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            TextButton(
              onPressed: () {
                setState(() {
                  is_select = !is_select;
                  Provider.of<StoreCountModel>(context,listen: false).selectAll(is_select);
                });
              },
              child: Row(
                children: [
                  Image.asset(
                    is_select == false
                        ? 'assets/images/common/login_check_button_normal@2x.png'
                        : 'assets/images/common/login_check_button_select@2x.png',
                    width: 20,
                    height: 20,
                  ),
                  Text(
                    ' 全选',
                    style: TextStyle(
                      color: Colors.black87,
                      fontSize: 13,
                    ),
                  ),
                ],
              ),
            ),
            _allCountWidget(),
          ],
        ));
  }

  /// 合计 && 结算
  Widget _allCountWidget() {
    return Row(
      children: [
        RichText(
          text: TextSpan(
            text: '合计:   ',
            style: TextStyle(
              fontSize: 14,
              color: AppColors.black,
            ),
            children: [
              TextSpan(
                text:
                    '¥${(NumUtil.getNumByValueDouble(Provider.of<StoreCountModel>(context).allPrice, 2))}',
                style: TextStyle(
                    fontSize: 16,
                    color: Colors.redAccent,
                    fontWeight: FontWeight.w400),
              ),
            ],
          ),
        ),
        SizedBox(
          width: 15,
        ),
        Container(
          alignment: Alignment.center,
          color: AppColors.yellow,
          width: 80,
          height: 45,
          child: Text(
            '结算: ${(NumUtil.getNumByValueDouble(Provider.of<StoreCountModel>(context).allPrice, 2))}',
            style: TextStyle(
              color: Colors.black87,
              fontSize: 14,
            ),
          ),
        )
      ],
    );
  }
}
